import React, { Component, Fragment } from "react";
// antd
import { Dropdown, Menu, Table, Button, Col, Pagination, Form, Select, Typography, Space, Tag, Input, message, Modal, Switch, Divider, Checkbox, Popover, notification } from "antd";
import Action from "@c/buttonAction/Index";
import { DownOutlined, CheckOutlined, CopyOutlined } from '@ant-design/icons';
import {CopyToClipboard} from 'react-copy-to-clipboard';

// http
import http from '../../../utils/request';

// 维护数据
import { maintain_date } from "../../../utils/common";

// import XLSX from "xlsx"
import ExportJsonExcel from "js-export-excel";
import { cmdb_sheet_filter, cmdb_sheet_header, cmdb_sheet_name, pagination_size_option } from "../../../utils/common"


const { Text, Link } = Typography;
const { Option } = Select;
const { TextArea } = Input;


function ListItem(props) {
    return <div><Link href="">{props.value}</Link></div>
}

class Nas extends Component {
    constructor(props){
        super(props)
        this.state = {
            loading: false,

            // 分页
            total: '',
            page: 1,
            page_number: 10,

            // 搜索
            search_instance_id: null,
            search_mount_domain: null,
            search_business: null,
            search_division: null,
            search_instance_platform: null,
            search_instance_account_name: null,
            search_alarm_status: null,
            search_charge_type: null,
            search_option_account: [],
            search_option_platform: [],
            label_list_option: [],
            label_list_option_name: [],
            label_division_list_option: [],
            label_division_list_option_name: [],
            label_nas_list: null,

            visable_label: false,
            visable_label_division: false,
            visable_maintain: false,
            loading_label: false,

            selectedRowKeys: [],

            // 维护
            metric_instance_id: null,
            metric_list: [],
            metric_list_column: [{
                key:'metric',
                value: maintain_date
            }],
            metric_list_select: [],
            maintain_key: [],

            // 表格
            dataSource: [],
            columns: [
                {title: "实例ID/名称", dataIndex: "instance_id", key: "instance_id",
                    render: (text, rowData) => {
                        return(
                            <Space direction="vertical">
                                <CopyToClipboard text={rowData.instance_id} 
                                    onCopy={() => 
                                        this.setState({copied: true},
                                        notification.open({
                                            message: '已复制到剪贴板',
                                            icon: <CheckOutlined style={{ color: 'green' }} />,
                                            duration: 2,
                                            placement: 'top',
                                        })
                                    )}
                                >
                                    <span><span style={{marginRight: "5px"}}><CopyOutlined /></span><span style={{color: "#6587FF"}}>{rowData.instance_id}</span></span>
                                </CopyToClipboard>
                                 
                                <Text >{rowData.name}</Text>
                            </Space>
                        )
                    }
                },
                {title: "云平台", dataIndex: "cloud-platform", key: "cloud-platform",
                    render: (text, rowData) => {
                        return(
                            <div>
                                <Tag color="green">{rowData.platform}-{rowData.account_name}</Tag>                                
                            </div>
                        )
                    }
                },
                {title: "区域", dataIndex: "region", key: "region",
                    render: (text, rowData) => {
                        return(
                            <div>
                                <Tag color="green">{rowData.region}</Tag>
                            </div>
                        )
                    }
                },
                {title: "财务", dataIndex: "division", key: "division", width: "160px",
                    render: (text, rowData) => {
                        return(
                            <div>
                                <Tag color="green">{rowData.division}</Tag>
                            </div>
                        )
                    }
                },
                {title: "告警", dataIndex: "business", key: "business", width: "160px",
                    render: (text, rowData) => {
                        return(
                            <div>
                                <Tag color="green">{rowData.business}</Tag>
                            </div>
                        )
                    }
                },
                {title: "业务域名", dataIndex: "mount_domain", key: "mount_domain", width: "360px",
                    render: (text, rowData) => {
                        const listItems = rowData.mount_domain.map((item) => 
                                <ListItem key={item.toString()} value={item} />
                        );
                        return (
                            <ul>{listItems}</ul>
                        )
                    }
                },
                {title: '过期时间', dataIndex: "expire_time", key: "expire_time"},
                {title: "付费类型", dataIndex: "charge_type", key: "charge_type",
                    render: (text, rowData) => {
                        return(
                            <div>
                                <Tag color="magenta">{rowData.charge_type}</Tag>
                            </div>
                        )
                    }
                },
                {title: "实例类型", dataIndex: "instance_type", key: "instance_type"},

                {title: "已用空间(GB)", dataIndex: "storage_used", key: "storage_used", defaultSortOrder: 'descend', sorter: (a, b) => a.storage_used - b.storage_used,
                    render: (text, rowData) => {
                        return(
                            <div>
                                <Tag color="green">{rowData.storage_used}</Tag>                                
                            </div>
                        )
                    }
                },
                {title: "存储空间(GB)", dataIndex: "storage_total", key: "storage_total", defaultSortOrder: 'descend', sorter: (a, b) => a.storage_total - b.storage_total,
                    render: (text, rowData) => {
                        return(
                            <div>
                                <Tag color="blue">{rowData.storage_total}</Tag>                                
                            </div>
                        )
                    }
                },
                {title: "使用率(%)", dataIndex: "utilization_rate", key: "utilization_rate", defaultSortOrder: 'descend', sorter: (a, b) => a.utilization_rate - b.utilization_rate,
                    render: (text, rowData) => {
                        return(
                            <div>
                                <Tag color="blue">{rowData.utilization_rate}</Tag>                                
                            </div>
                        )
                    }
                },
                {title: "接警状态", dataIndex: "alarm_status", key: "alarm_status",
                    render: (text, rowData) => {
                        return (
                            <Switch 
                                size="small" 
                                defaultChecked={rowData.alarm_status} 
                                onClick={() => this.onChangeAlarmStatus(rowData.id)} 
                            />
                        )
                    }
                },
                {title: "操作", dataIndex: "operation", key: "operation", fixed: 'right',
                    render: (text, rowData) => {
                        return (
                            <div className="inline-button">
                                <Action>
                                    <Action.Button onClick={() => this.onAlarmMaintainBtn(rowData)}>维护</Action.Button>
                                </Action>
                            </div>

                        )
                    }           
                }
            ],
        }
        this.formRefLabel = React.createRef();
        this.formRefMaintain = React.createRef();
        this.formRefLabelDivision = React.createRef();
    }

    componentDidMount() {
        this.loadData()
        this.loadDataPlatform()
        this.loadDataBusiness()
        this.loadDataDivision()
        this.loadDataPush()
    }

    loadDataPush = () => {
        const maintain_key = []
        for(var key in maintain_date) {
            if (key.length < 2){
                maintain_key.push(0+key)
            } else {
                maintain_key.push(key)
            }
        }
        this.setState({
            maintain_key: maintain_key
        })
    }

    loadDataBusiness = () => {
        const requestDataBusiness = {
            'page': 1,
            'limit': 1000,
        }
        http.get('/business', {params: requestDataBusiness}).then(response=>{
            const resp_data = response.data.data.items
            const label_list_option = []
            const label_list_option_name = []
            for (let i = 0; i < resp_data.length; i++) {
                label_list_option.push(<Option key={resp_data[i].id}>{resp_data[i].name}</Option>)
                label_list_option_name.push(<Option key={resp_data[i].name}>{resp_data[i].name}</Option>)
            }
            label_list_option_name.push(<Option key='none'>空标签</Option>)
            this.setState({
                label_list_option: label_list_option,
                label_list_option_name: label_list_option_name
            })
        })
    }

    loadDataPlatform = () => {
        const requestData = {
            'page': 1,
            'limit': 1000,
        }
        http.get('/cloud/platform', {params: requestData}).then(response=>{
            const search_option_platform = []
            const resp_data = response.data.data.items
            for (let i = 0; i < resp_data.length; i++) {
                search_option_platform.push(<Option key={resp_data[i].name}>{resp_data[i].name}</Option>)
            }
            this.setState({
                search_option_platform: search_option_platform
            })
        })
    }

    loadDataDivision = () => {
        const requestDataBusiness = {
            'page': 1,
            'limit': 1000,
        }
        http.get('/division', {params: requestDataBusiness}).then(response=>{
            const resp_data = response.data.data.items
            const label_division_list_option = []
            const label_division_list_option_name = []
            for (let i = 0; i < resp_data.length; i++) {
                label_division_list_option.push(<Option key={resp_data[i].id}>{resp_data[i].name}</Option>)
                label_division_list_option_name.push(<Option key={resp_data[i].name}>{resp_data[i].name}</Option>)
            }
            label_division_list_option_name.push(<Option key='none'>空标签</Option>)
            this.setState({
                label_division_list_option: label_division_list_option,
                label_division_list_option_name: label_division_list_option_name
            })
        })
    }

    loadData = () => {
        this.setState({
            loading: true
        })
        const requestData = {
            'page': this.state.page,
            'limit': this.state.page_number,
            'instance_id__contains': this.state.search_instance_id,
            'mount_domain__contains': this.state.search_mount_domain,
            'business': this.state.search_business,
            'division': this.state.search_division,
            'platform': this.state.search_instance_platform,
            'account_name': this.state.search_instance_account_name,
            'alarm_status': this.state.search_alarm_status,
            'charge_type': this.state.search_charge_type,
        }
        // 获取列表
        http.get('/cloud/nas', {params: requestData}).then(response=>{
            this.setState({
                dataSource: response.data.data.items,
                total: response.data.data.pages.total,
                loading: false
            })
        }).catch()
    }

    // 切换每页数量
    onChangeSizePage = (page, page_number) => {
        this.setState({
            page: page,
            page_number: page_number,
        }, () => {
            this.loadData()
        })
        this.loadData()
    }    


     /** 搜索 */
    onFinishSearch = (data) => {
        this.setState({
            search_instance_id: data.instance_id ? data.instance_id : null,
            search_mount_domain: data.mount_domain ? data.mount_domain : null,
            search_instance_platform: data.platform,
            search_instance_account_name: data.account_name,
            search_business: data.business,
            search_division: data.division,
            search_alarm_status: data.alarm_status ? data.alarm_status : null,
            search_charge_type: data.charge_type ? data.charge_type : null,
            page: 1
        })
        this.loadData()
    }

    // 搜索切换云平台
    onChangePlatform = (value) => {
        if (value) {
            this.setState({
                search_instance_platform: value
            })

            const requestData = {
                'page': 1,
                'limit': 1000,
                'platform': value
            }
    
            http.get('/cloud/account', {params: requestData}).then(response=>{
                const search_option_account = []
                const resp_data = response.data.data.items
                for (let i = 0; i < resp_data.length; i++) {
                    search_option_account.push(<Option key={resp_data[i].name}>{resp_data[i].name}</Option>)
                }
                this.setState({
                    search_option_account: search_option_account
                })
            })

        } else {
            this.setState({
                search_option_account: [],
            })
        }
    }

    // 搜索云账户
    onChangeAccountName = (value) => {
        this.setState({
            search_instance_account_name: value ? value : null
        })
    }

    // 搜索业务线
    onChangeBusiness = (value) => {
        this.setState({
            search_business: value ? value : null
        })
    }

    // 批量选中标签
    onSelectChange = (selectedRowKeys) => {
        this.setState({
            selectedRowKeys: selectedRowKeys
        })
    }

    // 批量打标签按钮
    onLabelBtn = () => {
        if (this.state.selectedRowKeys.length>0) {
            // 获取NAS列表
            const requestData = {
                instance_id_list: this.state.selectedRowKeys,
                operation_type: 'get_nas_list',
            }
            http.patch('/cloud/nas', {params: requestData}).then(response=>{
                const resp_data = response.data.data
                const resp_data_2 = resp_data.join("\n")
                this.setState({
                    label_nas_list: resp_data_2
                })

                this.formRefLabel.current.setFieldsValue({
                    label_nas_list:  resp_data_2
                })
            }).catch()

            this.setState({
                visable_label: true,
            })
        } else {
            message.info('请先选中需要打标签的资源实例')
        }
    }

    // 批量打标签任务取消
    onFinishLabelCancel = () => {
        this.formRefLabel.current.resetFields()
        this.setState({
            visable_label: false,
            selectedRowKeys: [],
        })
    }

    // 事业部批量打标签任务取消
    onFinishLabelDivisionCancel = () => {
        this.formRefLabelDivision.current.resetFields()
        this.setState({
            visable_label_division: false,
            selectedRowKeys: [],
        })
    }

    // 批量打标签任务提交
    onFinishLabel = (data) => {
        this.formRefLabel.current.resetFields()
        this.setState({
            loading_label: true
        })
        const requestData = {
            business_id: data.business_id,
            label_nas_list: data.label_nas_list,
            operation_type: 'change_label',
        }
        http.patch('/cloud/nas', {params: requestData}).then(response=>{
            this.setState({
                loading_label: false,
                visable_label: false,
                selectedRowKeys: [],
            })
            this.loadData()
        })
    }

    // 批量打标签任务提交
    onFinishLabelDivision = (data) => {
        this.formRefLabelDivision.current.resetFields()
        this.setState({
            loading_label: true
        })
        const requestData = {
            division_id: data.division_id,
            label_nas_list: data.label_nas_list,
            operation_type: 'change_label_division',
        }
        http.patch('/cloud/nas', {params: requestData}).then(response=>{
            this.setState({
                loading_label: false,
                visable_label_division: false,
                selectedRowKeys: [],
            })
            this.loadData()
        })
    }

    // 批量打事业部标签
    onLabelDivisionBtn = () => {
        if (this.state.selectedRowKeys.length>0) {

            // 获取主机列表
            const requestData = {
                instance_id_list: this.state.selectedRowKeys,
                operation_type: 'get_nas_list',
            }
            http.patch('/cloud/nas', {params: requestData}).then(response=>{
                const resp_data = response.data.data
                const resp_data_2 = resp_data.join("\n")
                this.setState({
                    label_nas_list: resp_data_2
                })

                this.formRefLabelDivision.current.setFieldsValue({
                    label_nas_list:  resp_data_2
                })
            }).catch()

            this.setState({
                visable_label_division: true,
            })
        } else {
            message.info('请先选中需要打标签的资源实例')
        }
    }

    // 变更接警状态
    onChangeAlarmStatus = (id) => {
        const requestData = {
            instance_id: id,
            operation_type: 'change_alarm_status',
        }
        http.patch('/cloud/nas', {params: requestData}).then(response=>{})
    }

    // 维护按钮
    onAlarmMaintainBtn = (rowData) => {
        const requestData = {
            resource_type: rowData.resource_type,
            platform: rowData.platform,
            operation_type: 'get_metric_list',
        }

        http.patch('/cloud/nas/' + rowData.instance_id, {params: requestData}).then(response=>{
            const metric_list_select = []
            const resp_data = response.data.data
            for (let i = 0; i < resp_data.length; i++) {
                metric_list_select.push(<Option key={resp_data[i]}>{resp_data[i]}</Option>)
            }
            this.setState({
                metric_list_select: metric_list_select,
                metric_instance_id: rowData.instance_id,
                visable_maintain: true
            })
        })
    }

    // 维护提交按钮
    onAlarmMaintainFinishAdd = (data) => {
        const requestData = {
            operation_type: 'change_metric_list',
            data: data
        }
        http.patch('/cloud/nas/' + this.state.metric_instance_id, {params: requestData}).then(response=>{
            this.setState({
                visable_maintain: false,
            })
            this.formRefMaintain.current.resetFields();
            message.success(response.data.msg)
        })
    }

    // 维护按钮取消
    onAlarmMaintainCancelBtn = () => {
        this.setState({
            visable_maintain: false,
            metric_list: [],
            metric_list_select: [],
            metric_instance_id: null,
            metric_list_column: [{
                key:'metric',
                value: maintain_date
            }],
        })
        this.formRefMaintain.current.resetFields();
    }

    // 维护列新增
    onAlarmMaintainAddColBtn = () => {
        this.state.metric_list_column.push({
            key:'metric',
            value: maintain_date
        })
        this.setState({
            metric_list_column: this.state.metric_list_column
        })
    }

    // 维护列删除
    onAlarmMaintainDelColBtn = () => {
        this.state.metric_list_column.pop()
        this.setState({
            metric_list_column: this.state.metric_list_column
        })
    }

    // 一键导出
    onexportExcelBtn = () => {
        // 不同云产品添加自定义字段
        const _cmdb_sheet_filter = cmdb_sheet_filter.concat('mount_domain', 'instance_type', 'storage_used', 'storage_total', 'utilization_rate')
        const _cmdb_sheet_header = cmdb_sheet_header.concat('业务域名', '实例类型', '已用空间', '存储空间', '使用率')

        let option = {}
        option.fileName = cmdb_sheet_name
        option.datas = [
            {
                sheetData: this.state.dataSource,
                sheetName: cmdb_sheet_name,
                sheetFilter: _cmdb_sheet_filter,
                sheetHeader: _cmdb_sheet_header
            }
        ]
        var toExcel = new ExportJsonExcel(option)
        toExcel.saveExcel()
    }

    render(){
        const { loading, columns, dataSource, page, total, search_option_platform, search_option_account, selectedRowKeys, visable_label,
                loading_label, label_list_option, label_list_option_name, visable_maintain, metric_list_column, metric_list_select,
                maintain_key, visable_label_division, label_division_list_option, label_division_list_option_name
        } = this.state
        const rowSelection = {
            selectedRowKeys,
            onChange: this.onSelectChange,
        }
        const content = (
            <div>
                <Link target="_blank" href="https://www.aliyun.com/price/product?spm=a2c4g.11186623.0.0.4aa430daxV6UfZ#/nas/detail/nas_bag">
                    阿里云NAS定价策略
                </Link>
            </div>
        );
        const operations = (
            <Menu
                items={[
                    {
                        label: (
                            <Action.Button onClick={() => this.onLabelBtn()}>业务线标签</Action.Button>
                        ),
                        key: '0',
                    },
                    {
                        label: (
                            <Action.Button onClick={() => this.onLabelDivisionBtn()}>事业部标签</Action.Button>
                        ),
                        key: '1',
                    },
                    {
                        label: (
                            <Action.Button onClick={() => this.onexportExcelBtn()} >导出页面数据</Action.Button>
                        ),
                        key: '2',
                    }
                ]}
            />
        );
        var myStyle = {margin: '20px'}
        var myStyle1 = {margin: '10px', float: 'right'}
        var myStyle3 = {margin: '15px'}
        var myStyle4 = {margin: '15px'}
        var myStyleForm = {marginRight: '10px', marginTop: '5px'}


        return (
            <Fragment>
                <Form layout="inline" onFinish={this.onFinishSearch} size="small">

                    <Form.Item label="实例ID" name="instance_id" style={myStyleForm}>
                        <Input placeholder="实例ID"  />
                    </Form.Item>     

                    <Form.Item label="挂载域名" name="mount_domain" style={myStyleForm}>
                        <Input placeholder="挂载域名" />
                    </Form.Item>       

                    <Form.Item label="云平台" name="platform" style={myStyleForm}>
                        <Select
                            allowClear
                            showSearch
                            style={{ width: 200 }}
                            placeholder="请选择区域"
                            optionFilterProp="children"
                            onChange={this.onChangePlatform}
                            filterOption={(input, option) =>
                            option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                            }
                        >
                            {search_option_platform}
                        </Select>
                    </Form.Item>

                    <Form.Item label="云账户" name="account_name" style={myStyleForm}>
                        <Select
                            allowClear
                            showSearch
                            style={{ width: 200 }}
                            placeholder="请选择云账户"
                            onChange={this.onChangeAccountName}
                            >
                            {search_option_account}
                        </Select>                      
                    </Form.Item>

                    <Form.Item label="业务线搜索" name="business" style={myStyleForm}>
                        <Select
                            allowClear
                            showSearch
                            style={{ width: 180 }}
                            placeholder="请选择区域"
                            optionFilterProp="children"
                            onChange={this.onChangeBusiness}
                            filterOption={(input, option) =>
                            option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                            }
                        >
                            {label_list_option_name}
                        </Select>
                    </Form.Item>

                    <Form.Item label="事业部搜索" name="division" size="small" style={myStyleForm}>
                        <Select
                            allowClear
                            showSearch
                            style={{ width: 180 }}
                            placeholder="请选择事业部"
                            optionFilterProp="children"
                            // onChange={this.onChangeDivision}
                            filterOption={(input, option) =>
                            option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                            }
                        >
                            {label_division_list_option_name}
                        </Select>
                    </Form.Item>

                    <Form.Item label="付费类型" name="charge_type" size="small" style={myStyleForm}>
                        <Select
                            allowClear
                            showSearch
                            style={{ width: 200 }}
                            placeholder="查询付费类型"
                            >
                            <Option key="包年包月">包年包月</Option>
                            <Option key="按量付费">按量付费</Option>
                        </Select>                      
                    </Form.Item>

                    <Form.Item label="接警状态" name="alarm_status" style={myStyleForm}>
                        <Select
                            allowClear
                            showSearch
                            style={{ width: 200 }}
                            placeholder="查询接警状态"
                            >
                            <Option key={false}>禁用</Option>
                        </Select>                      
                    </Form.Item>
     
                    <Form.Item shouldUpdate={true} style={myStyleForm}>
                        <Button type="primary" htmlType="submit">搜索</Button>
                    </Form.Item>
                </Form>

                <div style={myStyle1}>
                    <Popover content={content} >
                        <img src="https://yunwei-public.oss-cn-zhangjiakou.aliyuncs.com/ops/common/help.png" alt="logo" style={{ height: '16px'}}/>
                    </Popover>
                </div>
                {/* <div style={myStyle1}><Button type="primary" onClick={() => this.onLabelBtn()} >批量打标签</Button></div> */}
                <div style={myStyle1}>
                    <Dropdown overlay={operations}>
                        <Action.Button>
                            <Space>
                                更多操作
                                <DownOutlined />
                            </Space>
                        </Action.Button>
                    </Dropdown>
                </div>


                <Table
                    size="small"
                    pagination={false} 
                    rowSelection={rowSelection} 
                    rowKey="id" 
                    columns={columns} 
                    dataSource={dataSource}
                    loading={loading}
                    scroll={{ y: 600, x: 2000 }}
                >
                </Table>

                <div style={myStyle}>
                    <Col span={16}>
                        <Pagination
                            onChange={this.onChangeSizePage}
                            current={page}
                            total={total}
                            pageSizeOptions={pagination_size_option}
                            showSizeChanger
                            showQuickJumper
                            showTotal={total => `Total ${total} items`}
                        />
                    </Col>
                </div>

                <Modal
                    title="批量打标签"
                    visible={visable_label}
                    onCancel={this.onFinishLabelCancel}
                    okText="确认"
                    cancelText="取消"
                    footer={null}
                    width="800px"
                >
                    <Form
                        onFinish={this.onFinishLabel}
                        ref={this.formRefLabel}
                        labelCol={{ span: 5 }}
                        wrapperCol={{ span: 14 }}
                    >

                        <Form.Item label="NAS列表" name="label_nas_list">
                            <TextArea disabled autoSize={true}></TextArea>
                        </Form.Item>

                        <Form.Item label="业务列表" name="business_id">
                        <Select
                            allowClear
                            showSearch
                            style={{ width: 200 }}
                            placeholder="请选择业务线"
                            optionFilterProp="children"
                            filterOption={(input, option) =>
                                option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                            }
                        >
                            {label_list_option}
                        </Select>
                    </Form.Item>

                        <Form.Item>
                            <Button loading={loading_label} htmlType="submit" type="primary">确定</Button>
                        </Form.Item>                                                               
                    </Form>           
                </Modal>

                <Modal
                    title="批量打标签"
                    visible={visable_label_division}
                    onCancel={this.onFinishLabelDivisionCancel}
                    okText="确认"
                    cancelText="取消"
                    footer={null}
                    width="800px"
                >
                    <Form
                        onFinish={this.onFinishLabelDivision}
                        ref={this.formRefLabelDivision}
                        labelCol={{ span: 5 }}
                        wrapperCol={{ span: 14 }}
                    >

                        <Form.Item label="NAS列表" name="label_nas_list">
                            <TextArea disabled autoSize={true}></TextArea>
                        </Form.Item>

                        <Form.Item label="事业部列表" name="division_id">
                        <Select
                            allowClear
                            showSearch
                            style={{ width: 200 }}
                            placeholder="请选择事业部"
                            optionFilterProp="children"
                            filterOption={(input, option) =>
                                option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                            }
                        >
                            {label_division_list_option}
                        </Select>
                    </Form.Item>

                        <Form.Item>
                            <Button loading={loading_label} htmlType="submit" type="primary">确定</Button>
                        </Form.Item>                                                               
                    </Form>           
                </Modal>                                
                <Modal
                    title="告警指标维护周期"
                    visible={visable_maintain}
                    onCancel={this.onAlarmMaintainCancelBtn}
                    okText="确认"
                    cancelText="取消"
                    footer={null}
                    width={1300}
                >
                    <div style={myStyle3}>
                        <Button onClick={this.onAlarmMaintainAddColBtn}>新增</Button>
                        <Button onClick={this.onAlarmMaintainDelColBtn}>删除</Button>
                        （如果选中了多个相同的指标，则最上层的指标维护规则生效）
                    </div>

                    <div style={myStyle4}>
                        <Form
                            onFinish={this.onAlarmMaintainFinishAdd}
                            ref={this.formRefMaintain}
                            labelCol={{ span: 5 }}
                            wrapperCol={{ span: 14 }}
                        >
                            {
                                metric_list_column.map((item, index)=>(
                                    <Space size={[8, 16]} wrap>
                                        <Form.Item 
                                            name={item.key + '-key-' + index}
                                            rules={[{required: true}]}
                                        >
                                            <Select
                                                allowClear
                                                showSearch
                                                style={{ width: 400 }}
                                                placeholder="请选择度量指标"
                                                optionFilterProp="children"
                                                filterOption={(input, option) =>
                                                    option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                                }
                                                >
                                                {metric_list_select}
                                            </Select>
                                        </Form.Item>

                                        <Form.Item 
                                            name={item.key + '-value-' + index}
                                            rules={[{required: true}]}
                                        >
                                            <Select
                                                mode="multiple"
                                                allowClear
                                                showSearch
                                                style={{ width: 400 }}
                                                placeholder="请选择维护时间段"
                                                optionFilterProp="children"
                                                dropdownRender={menu=>(
                                                    <div>
                                                        {menu}
                                                        <Divider style={{margin:'1px 1px'}}/>
                                                        <div style={{margin: "10px 10px"}}>
                                                            <Checkbox  onChange={(e) => {e.target.checked && this.formRefMaintain.current.setFieldsValue({ [item.key + '-value-' + index] : maintain_key} ) }} >全选</Checkbox>
                                                        </div>
                                                    </div>
                                                )}
                                            >
                                                {
                                                    item.value.map(el=>(
                                                        <Option value={el.key}>{el.value}</Option>
                                                    ))
                                                }
                                            </Select>
                                        </Form.Item>
                                    </Space>
                                ))
                            }
                            <Form.Item>
                                <Button loading={false} htmlType="submit" type="primary">确定</Button>
                            </Form.Item>  
                        </Form>
                    </div>
                </Modal>

            </Fragment>
        )
    }
}

export default Nas;